import 'package:flutter/material.dart';
import 'package:get/get.dart';
import 'package:tiktokadult/hj_model/video_model.dart';

class PostPreOrNextWidget extends StatelessWidget {
  final String? id;
  final List<VideoModel>? videoArr;
  final Function(String? id)? next;
  final Function(String? id)? pre;

  const PostPreOrNextWidget({super.key, this.id, this.videoArr, this.next, this.pre});

  @override
  Widget build(BuildContext context) {
    if (videoArr == null || videoArr?.isEmpty == true || videoArr?.length == 1) {
      return SizedBox();
    }
    List<VideoModel> videos = videoArr ?? [];
    VideoModel? preModel;
    VideoModel? nextModel;
    for (int i = 0; i < videos.length; i++) {
      VideoModel model = videos[i];
      if (model.id == id) {
        if (i == 0) {
          nextModel = videos[i + 1];
        } else if (i == videos.length - 1) {
          preModel = videos[i - 1];
        } else {
          preModel = videos[i - 1];
          nextModel = videos[i + 1];
        }
      }
    }
    return Container(
      padding: EdgeInsets.symmetric(vertical: 16),
      margin: EdgeInsets.symmetric(horizontal: 12),
      decoration: BoxDecoration(
        border: Border(
          bottom: BorderSide(color: Colors.white.withOpacity(0.1)),
        ),
      ),
      child: Row(
        crossAxisAlignment: CrossAxisAlignment.start,
        children: [
          Expanded(
            child: preModel != null
                ? InkWell(
                    onTap: () {
                      pre?.call(preModel?.id);
                      // Get.toNamed(PostDetailPage.routeName,
                      //     arguments: PostDetailPageArgument(id: preModel?.id, videoModels: videoArr));
                    },
                    child: Column(
                      mainAxisSize: MainAxisSize.min,
                      crossAxisAlignment: CrossAxisAlignment.start,
                      children: [
                        Text(
                          "上一篇",
                          style: TextStyle(
                            color: Colors.white,
                            fontSize: 16,
                          ),
                        ),
                        SizedBox(height: 6),
                        Text(
                          preModel.title ?? "    ",
                          maxLines: 2,
                          style: TextStyle(
                            color: Color(0xff999999),
                            fontSize: 14,
                            height: 1.5,
                          ),
                        ),
                      ],
                    ),
                  )
                : SizedBox(),
          ),
          SizedBox(width: 24),
          Expanded(
            child: (nextModel != null && nextModel.id != null)
                ? InkWell(
                    onTap: () {
                      next?.call(nextModel?.id);
                      // Get.toNamed(PostDetailPage.routeName,
                      //     arguments: PostDetailPageArgument(id: nextModel?.id, videoModels: videoArr));
                    },
                    child: Column(
                      mainAxisSize: MainAxisSize.min,
                      crossAxisAlignment: CrossAxisAlignment.end,
                      children: [
                        Text(
                          "下一篇",
                          style: TextStyle(
                            color: Colors.white,
                            fontSize: 16,
                          ),
                        ),
                        SizedBox(height: 6),
                        Text(
                          nextModel.title ?? "     ",
                          maxLines: 2,
                          style: TextStyle(
                            color: Color(0xff999999),
                            fontSize: 14,
                            height: 1.5,
                          ),
                        ),
                      ],
                    ),
                  )
                : SizedBox(),
          ),
        ],
      ),
    );
  }
}
